#pragma once

#include "commonheader.h"

typedef int (*ReadFunction)(char*buf, long buflen, LPVOID argv);

class CTCPSocket
{
public:
	CTCPSocket(ReadFunction cb, LPVOID argv, std::string ip="", USHORT port=80);
	CTCPSocket(SOCKET sock, ReadFunction cb, LPVOID argv);
	~CTCPSocket();
	BOOL Start();
	void Stop();
	int Write(char*buf, long buflen);
private:
	SOCKET mSocket;
	BOOL mConnected;
	BOOL mIsAlive;
	ReadFunction mReadFunction;
	std::string mIp;
	USHORT mPort;
	LPVOID mArgv;
	std::thread *mThread;
	static void ThreadFunction(LPVOID argv);
};

